from functools import wraps
from flask import g, redirect, url_for


def login_required(func):
    @wraps(func)#保留func的信息
    def inner(*args,**kwargs):#*未知数量的参数，**代表关键字参数
        if g.user:
            return func(*args,**kwargs)
        else:
            return redirect(url_for("auth.login"))#redirect('/auth/login')
    return inner

#举例
# @login_required
# def public_question(question_id):
#     pass
#
# login_required(public_question)(question_id)